const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');

// 禁用硬件加速可能会解决某些视频播放问题
// app.disableHardwareAcceleration();

// 直播地址配置
const STREAM_URLS = {
  hls: 'http://10.120.22.196:10086/hls/ZKby23IHg/playlist.m3u8',
  rtmp: 'rtmp://10.120.22.196:10035/live/ZKby23IHg'
};

function createWindow() {
  const mainWindow = new BrowserWindow({
    width: 1200,
    height: 700,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: true
    },
    autoHideMenuBar: true,
    icon: path.join(__dirname, 'assets/icon.png')
  });

  mainWindow.loadFile('index.html');
  mainWindow.setAutoHideMenuBar(false);
  
  // 开发环境下打开开发者工具
  if (process.env.NODE_ENV === 'development') {
    mainWindow.webContents.openDevTools();
  }
}

app.whenReady().then(() => {
  createWindow();

  app.on('activate', function () {
    if (BrowserWindow.getAllWindows().length === 0) createWindow();
  });
});

app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') app.quit();
});

// 向渲染进程提供直播地址
ipcMain.handle('get-stream-urls', () => {
  return STREAM_URLS;
});